# **************************************
# --*-- coding: utf-8 --*--
# @Time    : 2024-09-25
# @Author  : white
# @FileName: __init__.py.py
# @Software: PyCharm
# **************************************
from tkinter import Tk, LEFT, Frame, Canvas, Scrollbar, W
from tkinter import W
from tkinter import messagebox


class Window(Tk):

    def __init__(self, width=420, height=260):
        super().__init__()
        self.width = width
        self.height = height

        self.update_position()

        # self.minsize(width=width, height=height)
        # self.maxsize(width=width + change_width, height=height + change_height)
        self.resizable(False, False)

        self.title("tools")
        self.icon_path = "tools.ico"
        self.iconbitmap(self.icon_path)

        self.left_width = self.width // 3
        self.right_width = self.width - self.left_width

        self._row = -1

        self.padx = 5
        self.pady = 5
        self.pady_upper = (0, 5)

        self.left_window()
        self.right_window()

    @property
    def get_row(self):
        self._row += 1
        return self._row

    @property
    def get_now_row(self):
        return self._row

    def left_window(self):
        frame = Frame(self)
        frame.pack(side=LEFT, pady=self.pady, padx=self.padx)

        canvas = Canvas(frame)
        scrollbar = Scrollbar(frame, orient="vertical", command=canvas.yview)
        canvas.configure(yscrollcommand=scrollbar.set)

        canvas.grid(row=0, column=0, sticky=W)
        scrollbar.grid(row=0, column=1, sticky="ns")

        def config_func(event=None):
            canvas.configure(scrollregion=canvas.bbox("all"), width=self.left_width, height=self.height)

        self.left_frame = Frame(canvas)
        self.left_frame.pack()
        self.left_frame.bind("<Configure>", config_func)
        canvas.create_window((0, 0), window=self.left_frame, anchor='nw')

    def right_window(self):
        self.right_frame = Frame(self)
        self.right_frame.pack(side=LEFT, pady=self.pady, padx=self.padx)

    def show_msg(self, msg, _type="info"):
        if _type == "info":
            messagebox.showinfo(_type, msg)
        elif _type == "warning":
            messagebox.showwarning(_type, msg)
        elif _type == "error":
            messagebox.showerror(_type, msg)

    def update_position(self):
        self.geometry(f"{self.width}x{self.height}-{0}+{0}")

    def main(self):
        self.mainloop()

    def close_window(self):
        self.destroy()
